from collections import deque
class Solution:
    def floodFill(self, image: List[List[int]], sr: int, sc: int, newColor: int) -> List[List[int]]:
        if image[sr][sc] == newColor:
            return image
        queen = deque([(sr,sc)])
        m,n = len(image), len(image[0])
        color = image[sr][sc]
        image[sr][sc] = newColor
        while queen:
            x, y = queen.popleft()
            for dx, dy in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
                if 0<=dx< m and 0<=dy< n and image[dx][dy] == color:
                    image[dx][dy] = newColor
                    queen.append((dx, dy))
        return image